home *** CD-ROM | disk | FTP | other *** search
- Path: tech.cftnet.com!not-for-mail
- From: wcowley@cftnet.com (Wes Cowley)
- Newsgroups: comp.lang.c++
- Subject: Re: problem: static data in classes
- Date: 19 Feb 1996 10:35:08 GMT
- Organization: CFTnet
- Message-ID: <4g9jot$aur@tech.cftnet.com>
- References: <9602180123.AA22010@dcc11748.slip.digex.net>
- NNTP-Posting-Host: ppp244_4.cftnet.com
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- Steven D. Arnold (yami@digex.net) wrote:
- : [...]
- : class sample
- : {
- : public:
- : sample();
- :
- : private:
- : static int count;
- : };
- : [...]
- : Under MetroWerks, I get the error:
- :
- : Link Error : newtest.cpp: 'sample::count' referenced from
- : 'sample::sample()' is undefined.
- :
- : Under g++, I see:
- :
- : ld: Undefined symbol
- : sample::count
-
-
- You've declared sample::count but nowhere did you provide a definition
- for it. The definition is where space is actually allocated for the
- variable and is required as a static member variable doesn't get
- allocated with each instance.
-
- What the compilers are complaining about is a missing line like:
-
- int sample::count = 0;
-
- somewhere outside the class declaration.
-
- Wes
-